<template>
  <!--图表管理-->
  <div class="app-container">
    <el-form class="jc_search_wrap" v-model="searchList">
      <el-button @click=""><i class="el-icon-delete"></i>重新加载图表</el-button>
    </el-form>
    <el-button-group class="jc_btn_wrap jc_btn_left">
      <el-button @click="createRow"><i class="jc_icon el-icon-plus"></i>上传图标</el-button>
    </el-button-group>
    <el-table :data="list" v-loading.body="listLoading" element-loading-text="拼命加载中" border fit highlight-current-row class="jc_table_wrap"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="80px">
      </el-table-column>
      <el-table-column label='id' v-if="false">
        <template scope="scope">
          {{scope.row.id}}
        </template>
      </el-table-column>
      <el-table-column label='图标'>
        <template scope="scope">
          {{scope.row.name}}
        </template>
      </el-table-column>
      <el-table-column label='引用名称'>
        <template scope="scope">
          {{scope.row.createTime}}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination layout="prev, pager, next" :total="total" @current-change="changePage" :page-size="15"/>
    <!--新建-->
    <el-dialog title="新建角色" :visible.sync="create_visible" class="jc_dialog_wrap">
      <el-form :model="form_create" label-width="120px">
        <el-form-item label="角色名">
          <el-input v-model="form_create.name"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitCreateForm">确定</el-button>
        <el-button @click="create_visible=false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

  import * as User from "../../api/system";

  export default {
    components: {

    },
    data() {
      return {
        searchList: {
          search_LIKE_name: ''
        },
        list: null,
        total: 0,
        create_visible: false,
        detail_visible: false,
        edit_visible: false,
        form_create: {},
        form_detail: {},
        form_edit: {},
        multipleSelection: [],
      }

    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData(p=1) {
        this.listLoading = true;
        var params = this.searchList;
        params.page = p;
        User.getRoleList(params).then(data => {
          this.list = data.data.rows;
          this.total = parseInt(data.data.totalCount);
          this.listLoading = false;
        })

      },
      searchRows() {
        this.fetchData()
      },
      emptyInputs() {
        this.searchList = {
          search_LIKE_name: ''
        };
        this.fetchData()
      },
      createRow() {
        this.create_visible = true;
        this.form_create = {}
      },
      submitCreateForm() {
        User.createRole(this.form_create).then(data => {
          this.create_visible = false;
          this.fetchData();
        })
      },
      editRow() {
        if(this.multipleSelection.length === 0) {
          alert('请先勾选行');
        }else {
          User.searchRoleRow(this.multipleSelection[0].id).then(data => {
            this.edit_visible = true;
            this.form_edit = data.data;
          })
        }
      },
      submitEditForm() {
        User.updateRole(this.form_edit).then(data => {
          this.edit_visible = false;
          this.fetchData();
        })
      },
      detailRow(row) {
        User.searchRoleRow(row.id).then(data => {
          this.detail_visible = true;
          this.form_detail = data.data;
        })
      },
      deleteRow() {
      },
      permissionRow() {
        if(this.multipleSelection.length === 0) {
          alert('请先勾选行');
        }else {
          User.searchRoleRow(this.multipleSelection[0].id).then(data => {
            this.$router.push({path:'/system/menu',query: {data:data.data}})
          })
        }

      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      changePage(p) {
        this.fetchData(p)
      }
    },
    computed: {
      tableHeight() {
        const filterHeight = 28
        var tableHeight = this.getTableHeight(filterHeight)
        return tableHeight;
      }
    }
  }
</script>
